﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AgileZen.Models;

namespace AgileZen.Sample.Controllers
{
    public class TaskController : AgileZenController
    {
        public ActionResult Index(int projectid, int storyid, int id)
        {
            var project = AgileZenService.GetTask(projectId: projectid, storyId: storyid, taskId: id);

            return View(project);
        }

        public ActionResult Reorder(int projectid, int storyid)
        {
            try
            {
                //var 
                var story = AgileZenService.GetStory(storyid,projectid,Story.Enrichments.Tasks);
                var order = (from t in story.Tasks select t.Id).ToList<int>();
                
                

                var second = order.ElementAt(1);
                var third = order.ElementAt(2);

                order[1] = third;
                order[2] = second;

                var tasks = AgileZenService.ReorderTasks(storyid ,projectid, order.ToArray());
                return RedirectToAction("Index","Story", new { projectid = projectid });
            }
            catch
            {
                return View();
            }
        }
    }
}
